package com.example.rentsystem.service.impl;

import com.example.rentsystem.entity.Advice;
import com.example.rentsystem.mapper.AdviceMapper;
import com.example.rentsystem.service.AdviceService;
import com.example.rentsystem.utils.SqlUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.List;

public class AdviceServiceImpl implements AdviceService {

    @Override
    public boolean addAdvice(Advice advice) {
        try (SqlSession session = SqlUtil.getSession()) {
            AdviceMapper mapper = session.getMapper(AdviceMapper.class);
            return mapper.addAdvice(advice) == 1;
        }
    }

    @Override
    public boolean deleteAdvice(int id) {
        try (SqlSession session = SqlUtil.getSession()) {
            AdviceMapper mapper = session.getMapper(AdviceMapper.class);
            return mapper.deleteAdvice(id) == 1;
        }
    }

    @Override
    public List<Advice> getAdvices() {
        try (SqlSession session = SqlUtil.getSession()) {
            AdviceMapper mapper = session.getMapper(AdviceMapper.class);
            return mapper.getAdvices();
        }
    }
}
